import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:sptapp/moudle/common_info.dart';

import '../../basic/base_info.dart';
import '../../config/const.dart';
import '../../moudle/event_bus.dart';
import '../../widget/common_widget.dart';
import '../login/login.dart';

class MinSettingSecurityPage extends StatefulWidget {
  const MinSettingSecurityPage({super.key});

  @override
  State<MinSettingSecurityPage> createState() => _MinSettingSecurityPageState();
}

class _MinSettingSecurityPageState extends State<MinSettingSecurityPage> {


  List items = [
    {
      'img':'assets/home/min_product.png',
      'name':'Email'.tr,
      'value':baseUserInfo['email']??''
    },
    {
      'img':'assets/home/min_product.png',
      'name':'Password'.tr,
      'value':'Has been set'.tr
    },
  ];

  late StreamSubscription _subscription;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _subscription = eventBus.on<UserInfoChange>().listen((val){
      if(mounted){setState(() {
        items[0]['value'] = baseUserInfo['email']??'';
      });}
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _subscription.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: defaultBlackBgColor,
      appBar: myAppBar(context, 'Security'.tr),
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 48.w),
        child: Column(
          children: [
            SizedBox(height: 40.w,),
            Expanded(child: Container(
              child: SingleChildScrollView(
                child: Container(
                  padding: EdgeInsets.symmetric(horizontal: 40.w),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(16.w),
                      color: Color(0xff1e1d20)
                  ),
                  child: ListView.builder(itemBuilder: (ctx,index){
                    Map item = items[index];
                    return GestureDetector(
                      onTap: () {
                        if(index == 0){
                          Navigator.of(context).pushNamed('MinSecurityChangeEmail',arguments: {
                            'type':1
                          });
                        }else if(index == 1){
                          Navigator.of(context).pushNamed('MinPwdPage',arguments: {});
                        }
                      },
                      child: Container(
                        height: 120.w,
                        child: Column(
                          children: [
                            Expanded(child: Container(
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  // Image.asset(item['img'],width: 40.w,),
                                  // SizedBox(width: 8.w,),
                                  Expanded(child: Text(item['name'],style: TextStyle(
                                      color: Colors.white,
                                      fontWeight: FontWeight.w600,
                                      fontSize: 28.sp
                                  ),)),
                                  SizedBox(width: 24.w,),
                                  Container(
                                    child: Text(item['value'],style: TextStyle(
                                      color: Color.fromRGBO(255, 255, 255, 0.5),
                                      fontSize: 24.sp,
                                      fontWeight: FontWeight.w400
                                    ),),
                                  ),
                                  SizedBox(width: 0.w,),
                                  Image.asset('assets/common/control_right.png',width: 48.w,),
                                ],
                              ),
                            )),
                            Visibility(child: Container(
                              height: 1.w,
                              color: Color.fromRGBO(255, 255, 255, 0.1),
                            ),visible: index != item.length-1,),
                          ],
                        ),
                      ),
                    );
                  },padding: EdgeInsets.zero,shrinkWrap: true,physics: NeverScrollableScrollPhysics(),itemCount: items.length,),
                ),
              ),
            )),
            SizedBox(height: 32.w,),
            SizedBox(height: ScreenUtil().bottomBarHeight+10.w,)
          ],
        ),
      ),
    );
  }

}
